// CyTargetLinker,
// a Cytoscape plugin to extend biological networks with regulatory interaction
//
// Copyright 2011-2013 Department of Bioinformatics - BiGCaT, Maastricht University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package cytargetlinker;

import java.io.File;
import java.util.List;

import cytoscape.Cytoscape;
import cytoscape.task.Task;
import cytoscape.task.TaskMonitor;

/**
 * Cytoscape Task - progress bar while
 * the user network is extended
 */
public class IntegrationTask implements Task {
	
	private TaskMonitor taskMonitor;
	private CyTargetLinker linker;
	private List<File> rinFiles;
		
	public IntegrationTask(CyTargetLinker linker, List<File> files) {
		this.linker = linker;
		rinFiles = files;
	}

	public void setTaskMonitor(TaskMonitor monitor) throws IllegalThreadStateException {
		taskMonitor = monitor;
	}
	
	public void halt() {
		// not implemented
	}

	public String getTitle() {
		return "Load Regulatory Interaction Networks ...";
	}

	public void run() {
		taskMonitor.setStatus("Loading...");
		taskMonitor.setPercentCompleted(-1);
			
		// parses the matching edges from the regulatory interaction files
		RINHandler.getHandler().loadNetworks(rinFiles, linker);
		
		// creates a new network and adds the new nodes and edges
		linker.mergeNetworks();
			
		// creates the result panel
		linker.createColorTab();
		
		String status = "The following RINs have been loaded\n\n" + linker.getMessage();	
		Cytoscape.getNetworkView(linker.getResultNetwork().getName()).redrawGraph(true, false);
		
		linker.applyVisualStyle();
		taskMonitor.setStatus(status);
		taskMonitor.setPercentCompleted(100);
	}
}